#-*- coding: utf-8 -*-

from django.http import HttpResponsePermanentRedirect
from django.conf import settings

class Domain_transMiddleware(object):
    def process_request(self, request):
        base_url = settings.BASE_URL
        domain  = settings.DOMAIN
        if request.META['SERVER_NAME']!='localhost' and request.META['SERVER_NAME']!=domain:
            if request.META['QUERY_STRING']:
                new_url = base_url + request.path +'?'+ request.META['QUERY_STRING']
            else:
                new_url = base_url + request.path
            return HttpResponsePermanentRedirect(new_url)
